package cn.zymall.massage.controller;



import cn.zymall.common.model.ShortMessage;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.zymall.massage.service.ShortMessageService;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * (ShortMessage)表控制层
 *
 * @author makejava
 * @since 2020-08-24 10:08:11
 */
@RestController
@RequestMapping("shortMessage")
public class ShortMessageController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private ShortMessageService shortMessageService;


    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param shortMessage 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<ShortMessage> page, ShortMessage shortMessage) {
        return success(this.shortMessageService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.shortMessageService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param shortMessage 实体对象
     * @return 新增结果 110为参数与模板参数不对应 120为阿里云问题,联系开发人员
     */
    @PostMapping
    public R insert(@RequestBody ShortMessage shortMessage) {

        return success(this.shortMessageService.save(shortMessage));
    }

    /**
     * 修改数据
     *
     * @param shortMessage 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody ShortMessage shortMessage) {
        System.out.println(shortMessage);
        return success(this.shortMessageService.updateById(shortMessage));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {

        return success(this.shortMessageService.removeByIds(idList));
    }

}
